package com.example.yjhteam.controller;

import com.example.yjhteam.client.matchClient;
import com.example.yjhteam.entity.Teams;
import com.example.yjhteam.mapper.TeamsMapper;
import  com.example.common.vo.Result;
import com.example.yjhteam.service.ITeamsService;
import com.yc.yjh.biz.BizException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 队伍表 前端控制器
 * </p>
 *
 * @author ly
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/yjh/teams")
public class TeamsController {

    @Resource
    TeamsMapper teamsMapper;

    @Resource
    matchClient matchClient;

    @RequestMapping("query")
    public List<Teams> query(){
        return teamsMapper.findAll();
    }

    @RequestMapping("queryOne")
    public Map<String, Object> queryOne(@RequestParam("team_id") int teamId){
        return  teamsMapper.findOne(teamId);
    }

    @RequestMapping("selectMatchById")
    public Result selectMatchById(@RequestParam("mid") String mid){
        return matchClient.selectMatchById(mid);
    }

    @RequestMapping("selectMatchByName")
    public  Result selectMatchByName(@RequestParam("teamName") String teamName){
        return matchClient.selectMatchByName(teamName);
    }

    @Resource
    ITeamsService teamsService;

    @RequestMapping("teamData")
    public  Result getMatchById(String id,int page,int size){
        try {
            return Result.success("OK",teamsService.selectDataByTeamId(id,page,size));
        } catch (BizException e) {
            return Result.failure("业务异常");
        }
    }
}
